#define _CRT_SECURE_NO_WARNINGS 1
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */
struct ListNode* reverseList(struct ListNode* head) {
    struct ListNode* prev, * cur, * next;
    if (head == NULL) {
        return NULL;
    }
    prev = NULL;
    cur = head;
    next = head->next;
    while (cur) {
        cur->next = prev;
        prev = cur;
        cur = next;
        if (next)
            next = next->next;
    }
    return prev;
}